//
//  XMineViewController.m
//  iPlan
//
//  Created by 侯伟 on 2021/8/29.
//

#import "XMineViewController.h"
#import "RSSingleLineCell.h"
#import "Founction.h"
#import "ShareHanler.h"

#import "XFeedbackViewController.h"
#import "RSBaseWebViewController.h"

@interface XMineViewController ()

@property(nonatomic,strong) MyLinearLayout *contentLayout;

///
@property (nonatomic,weak)RSSingleLineCell* feedbackCell;

///
@property (nonatomic,weak)RSSingleLineCell* shareCell;

///
@property (nonatomic,weak)RSSingleLineCell* userProtocolCell;

///
@property (nonatomic,weak)RSSingleLineCell* privateProtocolCell;

@end

@implementation XMineViewController


- (void)loadView{
    [super loadView];
    // 线性布局
    MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:(MyOrientation_Vert)];
    rootLayout.backgroundColor = COLOR_BACKGEOUND;
    rootLayout.myMargin = 0;
    [self.view addSubview:rootLayout];
    
    //底部滚动控件
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    if (@available(iOS 11.0, *)) {
        scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
    } else {
        // Fallback on earlier versions
    }
    scrollView.myMargin = 0;
    scrollView.weight = 1.0;
    [rootLayout addSubview:scrollView];
    
    // 线性布局
    MyLinearLayout *contentLayout = [MyLinearLayout linearLayoutWithOrientation:(MyOrientation_Vert)];
    contentLayout.padding = UIEdgeInsetsZero;
    contentLayout.myHorzMargin = 0;
    contentLayout.myTop = 0;
    contentLayout.subviewVSpace = 10;
    contentLayout.heightSize.lBound(scrollView.heightSize, 10, 1);
    [scrollView addSubview:contentLayout];
    _contentLayout = contentLayout;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"我的";
    
    [self setupViews];
}


- (void)setupViews{
    
    RSSingleLineCell* feedbackCell = [RSSingleLineCell cellWithTitle:@"问题反馈"];
    feedbackCell.myHorzMargin = 0;
    feedbackCell.myTop = 10;
    feedbackCell.showSeparator = YES;
    feedbackCell.clickable = YES;
    feedbackCell.clickBlock = ^{
        [self feedbackClicked:NULL];
    };
    [self.contentLayout addSubview:feedbackCell];
    _feedbackCell = feedbackCell;;
    
    RSSingleLineCell* shareCell = [RSSingleLineCell cellWithTitle:@"分享APP"];
    shareCell.myHorzMargin = 0;
    shareCell.showSeparator = NO;
    shareCell.clickable = YES;
    shareCell.clickBlock = ^{
        [self shareClicked:NULL];
    };
    [self.contentLayout addSubview:shareCell];
    
    RSSingleLineCell* userProtocolCell = [RSSingleLineCell cellWithTitle:@"用户协议"];
    userProtocolCell.myHorzMargin = 0;
    userProtocolCell.showSeparator = YES;
    userProtocolCell.clickable = YES;
    userProtocolCell.clickBlock = ^{
        [self userProtocolClicked:NULL];
    };
    [self.contentLayout addSubview:userProtocolCell];
    _userProtocolCell = userProtocolCell;;
    
    RSSingleLineCell* privateProtocolCell = [RSSingleLineCell cellWithTitle:@"隐私协议"];
    privateProtocolCell.myHorzMargin = 0;
    privateProtocolCell.showSeparator = NO;
    privateProtocolCell.clickable = YES;
    privateProtocolCell.clickBlock = ^{
        [self privateProtocolClicked:NULL];
    };
    [self.contentLayout addSubview:privateProtocolCell];
}


#pragma mark  --- action
///反馈
- (void)feedbackClicked:(UIButton*)sender{
    XFeedbackViewController *feedback = [XFeedbackViewController new];
    [UIViewController showViewController:feedback animated:YES];
}

///分享
- (void)shareClicked:(UIButton*)sender{
    [ShareHanler share:[HApp name] image:[UIImage imageNamed:@"a_share_icon"] url:APP_STORE_URL];
}

///用户协议
- (void)userProtocolClicked:(UIButton*)sender{
    RSBaseWebViewController* web = [RSBaseWebViewController new];
    web.cutsomerTitle = YES;
    web.title = @"用户协议";
    web.URL = [NSURL URLWithString:APP_PROTOCOL_URL];
    [UIViewController showViewController:web animated:YES];
}

///隐私协议
- (void)privateProtocolClicked:(UIButton*)sender{
    RSBaseWebViewController* web = [RSBaseWebViewController new];
    web.cutsomerTitle = YES;
    web.title = @"隐私协议";
    web.URL = [NSURL URLWithString:APP_PRIVATE_URL];
    [UIViewController showViewController:web animated:YES];
}

@end
